using System;
using System.Collections;
using System.Collections.Generic;

namespace WXB
{
    public class Image
    {
        public Image(UIAtlas atlas, string name)
        {
            Atlas = atlas;
            Name = name;
            update();
        }

        UIAtlas Atlas;
        string Name;
        UISpriteData spriteData;

        public UIAtlas atlas { get { return Atlas; } set { if (Atlas == value) return; Atlas = value; update(); } }
        public string name { get { return Name; } set { if (Name == value) return; Name = value; update(); } }
        public UISpriteData SpriteData { get { return spriteData; } }

        void update()
        {
            if (Atlas == null)
                spriteData = null;
            else
            {
                spriteData = Atlas.GetSprite(Name);
            }
        }

        public float getWidth()
        {
            if (spriteData == null)
                return 0f;

            return spriteData.width;
        }

        public float getHeight()
        {
            if (spriteData == null)
                return 0f;

            return spriteData.height;
        }
    }
}